package com.hzqy.service.content;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

import javax.annotation.Resource;

import com.hzqy.commons.utils.*;
import com.hzqy.web.vo.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONArray;
import com.hzqy.commons.utils.sensitive.SensitiveMain;
import com.hzqy.persistence.dao.content.ContentDao;
import com.hzqy.persistence.dao.picture.PictureDao;
import com.hzqy.persistence.dao.wailian.WaiLianDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.service.pms.PmsServiceBean;
import com.hzqy.service.system.SysConfigServiceBeen;
import com.hzqy.web.vo.content.CmContentLedgerVo;
import com.hzqy.web.vo.system.SysConfigVo;

@Service
public class ContentServiceBean extends GenericServiceBean<CmContentVo, ContentDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private ContentDao contentDao;
	@Resource
	private PictureDao pictureDao;
	@Resource
	private SysConfigServiceBeen sysConfigServiceBeen;

	@Resource
	private PmsServiceBean pmsServiceBean;

	@Resource
	private WaiLianDao waiLianDao;

	@Override
	public ContentDao getEntityDao() {
		return contentDao;
	}

	/**
	 * 内容列表获取
	 * @param cmContentVo
	 * @param curPage
	 * @param pageSize
	 * @return
	 */
	public Map<String,Object> selectContentList(CmContentVo cmContentVo, int curPage,
												int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		cmContentVo.setF_cc_companyid(SQLCheckUtil.cleanXSS(cmContentVo.getF_cc_companyid()));
		cmContentVo.setF_cc_types(SQLCheckUtil.cleanXSS(cmContentVo.getF_cc_types()));
		if("0".equals(cmContentVo.getF_cc_companyid())) {
			cmContentVo.setF_cc_companyid("");
		}

		Integer rowCount = contentDao.findContentCount(cmContentVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_cc_name", cmContentVo.getF_cc_name());
			map.put("f_cc_name2", cmContentVo.getF_cc_name2());
			map.put("f_cc_status", cmContentVo.getF_cc_status());
			map.put("f_cc_companyid", cmContentVo.getF_cc_companyid());
			map.put("f_cc_searchname", cmContentVo.getF_cc_searchname());
			map.put("f_cc_type", cmContentVo.getF_cc_type());
			map.put("f_cc_types", cmContentVo.getF_cc_types());
			map.put("sctt_startDate", cmContentVo.getSctt_startDate());
			map.put("sctt_endDate", cmContentVo.getSctt_endDate());
			map.put("f_cc_transcodeStatus", cmContentVo.getF_cc_transcodeStatus());
			map.put("f_cc_programatype", cmContentVo.getF_cc_programatype());
			map.put("f_cc_actors", cmContentVo.getF_cc_actors());
			map.put("f_cc_productid", cmContentVo.getF_cc_productid());
			map.put("f_cc_mediacode", cmContentVo.getF_cc_mediacode());
			map.put("f_cc_duration", cmContentVo.getF_cc_duration());
			map.put("f_cc_obligate1", cmContentVo.getF_cc_obligate1());
			map.put("f_cc_obligate2", cmContentVo.getF_cc_obligate2());
			map.put("f_cc_category", cmContentVo.getF_cc_category());
			List<CmContentVo> results = contentDao.findContentList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<CmContentVo>());
		}
		return map;
	}

	/**
	 * 查询剧集列表
	 * @param cmSeriesVo
	 * @param curPage
	 * @param pageSize
	 * @return
	 */
	public Map<String,Object> selectSeriesList(CmSeriesVo cmSeriesVo, int curPage, int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = contentDao.findSeriesCount(cmSeriesVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_ssc_name", cmSeriesVo.getF_ssc_name());
			map.put("f_ssc_status", cmSeriesVo.getF_ssc_status());
			map.put("f_ssc_contentid", cmSeriesVo.getF_ssc_contentid());
			List<CmSeriesVo> results = contentDao.findSeriesList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<CmSeriesVo>());
		}
		return map;
	}

	/**
	 * 删除内容
	 * @param f_cc_id
	 * @return
	 */
	public int deleteContent(int f_cc_id) {
		contentDao.deleteContent(f_cc_id);
		return 1;
	}


	/**
	 * 删除剧集
	 * @param f_ssc_ids
	 * @return
	 */
	public int deleteSeries(int f_ssc_status,String f_ssc_ids) {
		contentDao.deleteSeries(f_ssc_status,f_ssc_ids);
		int f_ssc_id = 0;
		if(f_ssc_ids != null)
			f_ssc_id = Integer.parseInt(f_ssc_ids.split(",")[0]);
		CmSeriesVo csv = new CmSeriesVo();
		csv = contentDao.selectSeries(f_ssc_id);
		updateSeriseCount(csv.getF_ssc_contentid());
		return 1;
	}

	/**
	 * 增加内容---批量入库和单条入库都利用此方法
	 * @param contentVo
	 * @return
	 */
	public Map<String,Object> insertContent(CmContentVo contentVo,String picJson) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(contentVo==null || contentVo.getF_cc_name()==null) {
			flag = -1;
		}
		if(flag ==0) {
			Map<String, Object> name = SensitiveMain.sensitiveWordCheck(contentVo.getF_cc_name());
			Map<String, Object> desc = SensitiveMain.sensitiveWordCheck(contentVo.getF_cc_desc());
			if(contentVo.getF_cc_type()==100){
				resultMap =findContentList(contentVo,1);
				if(!(boolean)resultMap.get("success")){
					return resultMap;
				}
			}
			if(!(Boolean)name.get("hasSensitiveWord")&&!(Boolean)desc.get("hasSensitiveWord")){
				List<CmPicturesVo> picList = JsonUtils.jsonToPicVo(picJson);
				if(contentVo.getF_cc_code() != null)
					contentVo.setF_cc_code(contentVo.getF_cc_code().replaceAll(" ", ""));
				if(contentVo.getF_cc_type()==20&&contentVo.getSourceFlag()==5){
					if(picList.size()>0&&picList.get(0).getF_cp_cprid()==38){
						readDecompressionFile(SystemConfigUtils.getSysConfig("system_decompression_path")+picList.get(0).getF_cp_url(),contentVo);
					}
				}
				contentDao.insertContent(contentVo);
				int f_cc_id = contentVo.getF_cc_id();
				String arr[] = contentVo.getF_cc_companyid().split(",");
				for(int i=0;i<arr.length;i++){
					contentDao.insertContentOrg(f_cc_id, arr[i]);
				}
				if(contentVo.getF_cc_productid()!=null&&!"".equals(contentVo.getF_cc_productid().trim())){
					String productArr[] = contentVo.getF_cc_productid().split(",");
					for(int i=0;i<productArr.length;i++){
						contentDao.insertContentProduct(f_cc_id, productArr[i]);
					}
				}
				for(int i=0;i<picList.size();i++) {
					CmPicturesVo cmPicturesVo = new CmPicturesVo();
					cmPicturesVo = picList.get(i);
					cmPicturesVo.setF_cp_relationid(f_cc_id);
					pictureDao.insertPic(cmPicturesVo);
				}

				if(StringUtils.isNotEmpty(contentVo.getF_cast_id())) {
					String[] castIds = contentVo.getF_cast_id().split(",");
					for(int i=0;i<castIds.length;i++) {
						CmContentCastVo cmContentCastVo = new CmContentCastVo();
						cmContentCastVo.setF_ccast_castid(Integer.parseInt(castIds[i]));
						cmContentCastVo.setF_ccast_contentid(f_cc_id);
						cmContentCastVo.setF_ccast_viewindex(0);
						contentDao.insertContentCast(cmContentCastVo);
					}
				}
				//更新分类
				updateCatalogBind(f_cc_id,contentVo.getBind_categoryInStr(),contentVo.getBind_categoryDelStr(),contentVo.getOrgIds());
				if((contentVo.getF_cc_type()==0
						||contentVo.getF_cc_type()==2
						||contentVo.getF_cc_type()==3
						||contentVo.getF_cc_type()==4
						||contentVo.getF_cc_type()==5
						||contentVo.getF_cc_type()==110)&&contentVo.getSourceFlag()==5){//只记录内容类型操作
					//内容操作记录
					CmContentLedgerVo cmContentLedger=contentVo.getCmContentLedger();
					cmContentLedger.setF_ccl_type(1);
					cmContentLedger.setF_ccl_contentid(f_cc_id);
					cmContentLedger.setF_ccl_contentName(contentVo.getF_cc_name());
					insertCmContentLadger(cmContentLedger);//记录操作台账

				}

				resultMap.put("success", true);
				resultMap.put("result","新增内容成功!");
				resultMap.put("f_cc_id",f_cc_id);
			}else if((Boolean)name.get("hasSensitiveWord")){
				resultMap.put("success", false);
				resultMap.put("result","新增内容失败!含有敏感词："+name.get("sensitiveWordSet").toString());
				LOG.debug("新增内容失败!含有敏感词："+name.get("sensitiveWordSet").toString());
			}else if((Boolean)desc.get("hasSensitiveWord")){
				resultMap.put("success", false);
				resultMap.put("result","新增内容失败!含有敏感词："+desc.get("sensitiveWordSet").toString());
				LOG.debug("新增内容失败!含有敏感词："+desc.get("sensitiveWordSet").toString());
			}

		}else{
			resultMap.put("success", false);
			resultMap.put("result","新增内容失败!");
		}
		return resultMap;
	}


	/**
	 *
	 * @param contentVo
	 * @param flag 1 新增 2 修改
	 * @return
	 */
	private Map<String,Object> findContentList(CmContentVo contentVo,int flag) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.put("success", true);
		CmContentVo tmpVo = new CmContentVo();
		tmpVo.setF_cc_name(contentVo.getF_cc_name());
		tmpVo.setF_cc_type(contentVo.getF_cc_type());
		tmpVo.setF_cc_status(1);
		Map<String,Object> parammap = new HashMap<String, Object>();
		Integer rowCount = contentDao.findContentCount(tmpVo);
		parammap.put("f_cc_name", contentVo.getF_cc_name());
		parammap.put("f_cc_status", 1);
		parammap.put("f_cc_type", contentVo.getF_cc_type());
		parammap.put("firstResult", 0);
		parammap.put("maxResults", rowCount);
		List<CmContentVo> results = contentDao.findContentList(parammap);
		for(int i=0;results!=null && i<results.size();i++){
			String dbname = results.get(i).getF_cc_name();
			String dbcompanyName = results.get(i).getF_cc_companyname();
			LOG.debug("要修改的usersave账号:"+contentVo.getF_cc_name()+";dbname:"+dbname+";dbcompanyName:"+dbcompanyName);
			if(contentVo.getF_cc_name().equals(dbname)){
				if(flag == 1){
					resultMap.put("success", false);
					resultMap.put("result","新增失败!新增的账号已存在\""+dbcompanyName+"\"客户中!");
					LOG.debug("新增失败!新增的账号已存在\""+dbcompanyName+"\"客户中!");
				}else if(flag == 2){//修改
					//账号不变，客户重新选择一个，不应该有删除
					int f_cc_id = results.get(i).getF_cc_id();
					int userUpdateId = contentVo.getF_cc_id();
					//LOG.debug("userUpdateId:"+userUpdateId+";f_cc_id:"+f_cc_id+";name:"+results.get(i).getF_cc_name()+";orgId:"+results.get(i).getF_cco_orgId());
					//可能账号修改成别的客户下的账号
					if(f_cc_id!=userUpdateId){
						resultMap.put("success", false);
						resultMap.put("result","修改的账号已存在\""+dbcompanyName+"\"客户中,请从该客户中先删除此账号!");
						LOG.debug("修改的账号已存在\""+dbcompanyName+"\"客户中,请从该客户中先删除此账号!!");
						//int resflag = contentDao.deleteContent(f_cc_id);
					}
				}
				break;
			}
		}
		return resultMap;
	}

	/**
	 * 增加剧集
	 * @param cmSeriesVo
	 * @param picJson
	 * @return
	 */
	public int insertSeries(CmSeriesVo cmSeriesVo, String picJson) {
		int flag = 0;
		if(cmSeriesVo==null || cmSeriesVo.getF_ssc_name()==null) {
			flag = -1;
		}
		if(flag == 0) {
			contentDao.insertSeries(cmSeriesVo);
			updateSeriseCount(cmSeriesVo.getF_ssc_contentid());
			List<CmPicturesVo> picList = JsonUtils.jsonToPicVo(picJson);
			for(int i=0;i<picList.size();i++) {
				CmPicturesVo cmPicturesVo = new CmPicturesVo();
				cmPicturesVo = picList.get(i);
				cmPicturesVo.setF_cp_relationid(cmSeriesVo.getF_ssc_id());
				pictureDao.insertPic(cmPicturesVo);
			}
			return 1;
		}
		return flag;
	}

	/**
	 * 根据id查询内容详情
	 * @param f_cc_id
	 * @return
	 */
	public CmContentVo selectContent(int f_cc_id) {
		return contentDao.selectContent(f_cc_id);
	}

	/**
	 * 根据id查询剧集详情
	 * @param f_ssc_id
	 * @return
	 */
	public CmSeriesVo selectSeries(int f_ssc_id) {
		return contentDao.selectSeries(f_ssc_id);
	}

	/**
	 * 修改内容
	 * @param contentVo
	 * @return
	 */
	public Map<String,Object> updateContent(CmContentVo contentVo,String picJson,String picType,String change) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(contentVo==null || contentVo.getF_cc_name()==null) {
			flag = -1;
		}
		if(flag ==0) {
			Map<String, Object> name = SensitiveMain.sensitiveWordCheck(contentVo.getF_cc_name());
			Map<String, Object> desc = SensitiveMain.sensitiveWordCheck(contentVo.getF_cc_desc());
			if(contentVo.getF_cc_type()==100){
				resultMap = findContentList(contentVo,2);
				if(!(boolean)resultMap.get("success")){
					return resultMap;
				}
			}
			if(!(Boolean)name.get("hasSensitiveWord")&&!(Boolean)desc.get("hasSensitiveWord")){
				if("change".equals(change)){//企业被重新选择
					String arr[] = contentVo.getF_cc_companyid().split(",");
					contentDao.deleteContentOrg(contentVo.getF_cc_id());
					for(int i=0;i<arr.length;i++){
						contentDao.insertContentOrg(contentVo.getF_cc_id(),arr[i]);
					}
				}

				if(contentVo.getF_cc_productid()!=null&&!"".equals(contentVo.getF_cc_productid().trim())){
					contentDao.deleteContentProduct(contentVo.getF_cc_id());
					String productArr[] = contentVo.getF_cc_productid().split(",");
					for(int i=0;i<productArr.length;i++){
						contentDao.insertContentProduct(contentVo.getF_cc_id(), productArr[i]);
					}
				}

				List<CmPicturesVo> picList = JsonUtils.jsonToPicVo(picJson);
				String listPicId = JsonUtils.jsonToPicIdList(picJson);
				int f_cv_relationid = contentVo.getF_cc_id();
				Map<String,Object> picMap = new HashMap<String, Object>();
				picMap.put("listPicId", listPicId);
				picMap.put("f_cp_relationid", f_cv_relationid);
				picMap.put("picType", picType);
				CmContentVo cmContentVo =  contentDao.selectContent(f_cv_relationid);
				int status= cmContentVo.getF_cc_status();
				status = StatusConvert.updateStatusConvert(status);
				//修改请求为行业 特殊处理
				if(contentVo.getSourceFlag()==5){
					if(cmContentVo.getF_cc_type()==100||(cmContentVo.getF_cc_type()==2&&cmContentVo.getF_cc_status()==1)){//业务账户
						contentVo.setF_cc_status(status);
					}else{//模板与内容
						String roleId=contentVo.getRoleId();
						contentVo.setF_cc_status(2);//行业修改过都需要审核
						if(roleId!=null&&!"".equals(roleId)){//验证角色如果为省或者超级管理员则不改变内容状态
							String[] roleIdlist=roleId.split(",");
							for(int i=0;i<roleIdlist.length;i++){
								if(Integer.parseInt(roleIdlist[i])<=2||Integer.parseInt(roleIdlist[i])==10){//省公司修改后由自身进行再次审核 sp内容管理角色也直接由省审核
									contentVo.setF_cc_status(16);
								}
							}
						}
					}
					if(contentVo.getF_cc_type()==20){
						if(picList.size()>0&&picList.get(0).getF_cp_cprid()==38){
							readDecompressionFile(SystemConfigUtils.getSysConfig("system_decompression_path")+picList.get(0).getF_cp_url(),contentVo);
						}
					}
				}else{
					contentVo.setF_cc_status(status);
				}

				if(contentVo.getF_cc_code()!=null){
					contentVo.setF_cc_code(contentVo.getF_cc_code().replaceAll(" ", ""));
				}
				contentDao.updateContent(contentVo);
				pictureDao.deletePic(picMap);
				for(int i=0;i<picList.size();i++) {
					CmPicturesVo cmPicturesVo = new CmPicturesVo();
					cmPicturesVo = picList.get(i);
					cmPicturesVo.setF_cp_relationid(f_cv_relationid);
					pictureDao.insertPic(cmPicturesVo);
				}
				contentDao.deleteCastBind(contentVo.getF_cc_id());
				if(StringUtils.isNotEmpty(contentVo.getF_cast_id())){
					String[] castIds = contentVo.getF_cast_id().split(",");
					for(int i=0;i<castIds.length;i++) {
						CmContentCastVo cmContentCastVo = new CmContentCastVo();
						cmContentCastVo.setF_ccast_castid(Integer.parseInt(castIds[i]));
						cmContentCastVo.setF_ccast_contentid(contentVo.getF_cc_id());
						cmContentCastVo.setF_ccast_viewindex(0);
						contentDao.insertContentCast(cmContentCastVo);
					}
				}
				//更新分类
				updateCatalogBind(contentVo.getF_cc_id(),contentVo.getBind_categoryInStr(),contentVo.getBind_categoryDelStr(),contentVo.getOrgIds());
				if((contentVo.getF_cc_type()==0
						||contentVo.getF_cc_type()==2
						||contentVo.getF_cc_type()==3
						||contentVo.getF_cc_type()==4
						||contentVo.getF_cc_type()==5
						||contentVo.getF_cc_type()==110)&&contentVo.getSourceFlag()==5){//只记录内容类型操作当前只开发行业
					CmContentLedgerVo cmContentLedger=contentVo.getCmContentLedger();
					cmContentLedger.setF_ccl_type(2);
					cmContentLedger.setF_ccl_contentid(contentVo.getF_cc_id());
					cmContentLedger.setF_ccl_contentName(contentVo.getF_cc_name());
					insertCmContentLadger(cmContentLedger);//记录操作台账
				}

				resultMap.put("success", true);
				resultMap.put("result","修改内容成功!");
			}else if((Boolean)name.get("hasSensitiveWord")){
				resultMap.put("success", false);
				resultMap.put("result","修改内容失败!含有敏感词："+name.get("sensitiveWordSet").toString());
			}else if((Boolean)desc.get("hasSensitiveWord")){
				resultMap.put("success", false);
				resultMap.put("result","修改内容失败!含有敏感词："+desc.get("sensitiveWordSet").toString());
			}
		}else{
			resultMap.put("success", false);
			resultMap.put("result","修改内容失败!");
		}
		return resultMap;
	}

	/**
	 * 内容审核
	 * @param cmContentVo
	 * @return
	 */
	public int reviewContent(CmContentVo cmContentVo,PmsUserVo userVo) {
		int flag = 0;
		if(cmContentVo==null) {
			flag = -1;
		} else if (cmContentVo.getF_cc_status() !=1 && cmContentVo.getF_cc_status()!=4
				&& cmContentVo.getF_cc_status() != 5
				&& cmContentVo.getF_cc_status() != 13
				&& cmContentVo.getF_cc_status() != 14
				&& cmContentVo.getF_cc_status() != 15
				&& cmContentVo.getF_cc_status() != 16
				&& cmContentVo.getF_cc_status() != 17) {
			flag = -4;
		}
		if(flag == 0) {
			//权限判断

			CmContentVo oldContentVo=contentDao.selectContent(cmContentVo.getF_cc_id());
			if(cmContentVo.getSourceFlag()==5){
				//只改行业部分
				oldContentVo.setF_cc_viewindex(cmContentVo.getF_cc_viewindex());
				contentDao.updateContent(oldContentVo);

				String roleId=userVo.getRoleIds();
				if(roleId!=null&&!"".equals(roleId)){//验证角色如果为省或者超级管理员则不改变内容状态
					if("1".equals(userVo.getRoleIds())){//超级管理员
						//不做判断，随便改
					}else if("2".equals(userVo.getRoleIds())||(SystemConfigUtils.getSysConfig("review_province")+"").equals(userVo.getRoleIds())){//省管理员
						if((oldContentVo.getF_cc_type()!=2&&cmContentVo.getF_cc_status()==1)||(cmContentVo.getF_cc_status()==16||cmContentVo.getF_cc_status()==13||cmContentVo.getF_cc_status()==14||cmContentVo.getF_cc_status()==4)||cmContentVo.getF_cc_status()==15||cmContentVo.getF_cc_status()==5||cmContentVo.getF_cc_status()==17){
							//职则内操作
						}else{
							flag = -3;
						}
					}else if("3".equals(userVo.getRoleIds())||(SystemConfigUtils.getSysConfig("review_city")+"").equals(userVo.getRoleIds())){//市管理员
						if(cmContentVo.getF_cc_status()==16||cmContentVo.getF_cc_status()==4){
							//职则内操作
						}else{
							flag = -3;
						}
					}else if("8".equals(userVo.getRoleIds())||(SystemConfigUtils.getSysConfig("review_playcontrol")+"").equals(userVo.getRoleIds())){//播控管理员
						if(cmContentVo.getF_cc_status()==15||cmContentVo.getF_cc_status()==5||cmContentVo.getF_cc_status()==17){
							//职则内操作
						}else{
							flag = -3;
						}
					}else{
						String cityIds=SystemConfigUtils.getSysConfig("jurisdiction_city");
						if(cityIds!=null){//存在其他权限赋予
							boolean jurisdiction=false;
							String[] cityIdList=cityIds.split(",");
							for(int i=0;i<cityIdList.length;i++){
								if(cityIdList[i].equals(userVo.getRoleIds())){
									jurisdiction=true;
								}
							}
							if(jurisdiction){//与数据库赋予的权限一致
								if(cmContentVo.getF_cc_status()==16||cmContentVo.getF_cc_status()==4){
									//职则内操作
								}else{
									flag = -3;
								}
							}else{
								flag = -3;
							}
						}else{
							flag = -3;
						}
					}
				}else{
					flag = -3;
				}
				if(flag!=0){
					return flag;
				}
				if(oldContentVo.getF_cc_type()==20&&cmContentVo.getF_cc_status()==1){//模板类添加，且存在模板压缩包
					Map<String,String> picMap = new HashMap<String, String>();
					picMap.put("f_cp_relationid", oldContentVo.getF_cc_id()+"");
					picMap.put("picType", "模板");
					List<CmPicturesVo> picList=pictureDao.selectPictureList(picMap);
					if(picList.size()>0){
						flag=modelFileDecompression(oldContentVo,picList.get(0).getF_cp_url());
						if(flag!=0){
							return flag;
						}
					}
				}
				if(oldContentVo.getF_cc_type()==0
						||oldContentVo.getF_cc_type()==2
						||oldContentVo.getF_cc_type()==3
						||oldContentVo.getF_cc_type()==4
						||oldContentVo.getF_cc_type()==5
						||oldContentVo.getF_cc_type()==110){//只记录内容类型操作
					CmContentLedgerVo cmContentLedger=cmContentVo.getCmContentLedger();
					if(oldContentVo.getF_cc_status()==2||oldContentVo.getF_cc_status()==4){//市审核
						cmContentLedger.setF_ccl_type(3);
					}else if(oldContentVo.getF_cc_status()==16||oldContentVo.getF_cc_status()==13){//省审核
						cmContentLedger.setF_ccl_type(4);
					}else if(oldContentVo.getF_cc_status()==14||oldContentVo.getF_cc_status()==15){//牌照审核
						cmContentLedger.setF_ccl_type(5);
					}else{
						cmContentLedger.setF_ccl_type(13);
						cmContentLedger.setF_ccl_mac(""+oldContentVo.getF_cc_status());
					}
					cmContentLedger.setF_ccl_contentid(cmContentVo.getF_cc_id());
					cmContentLedger.setF_ccl_contentName(cmContentVo.getF_cc_name());
					insertCmContentLadger(cmContentLedger);//记录操作台账
				}
			}
			contentDao.reviewContent(cmContentVo);
			return 1;
		}
		return flag;
	}
	public int pretrialContent(CmContentVo cmContentVo,PmsUserVo userVo){
		CmContentVo oldContentVo=contentDao.selectContent(cmContentVo.getF_cc_id());
		oldContentVo.setF_ccc_viewindex(2);
		int flag=0;
		Map<String,String> picMap = new HashMap<String, String>();
		picMap.put("f_cp_relationid", cmContentVo.getF_cc_id()+"");
		picMap.put("picType", "模板");
		List<CmPicturesVo> picList=pictureDao.selectPictureList(picMap);
		if(picList.size()>0){
			flag=modelFileDecompression(oldContentVo,picList.get(0).getF_cp_url());
			if(flag!=0){
				return flag;
			}
		}
		return flag;
	}
	public int updateSeries(CmSeriesVo cmSeriesVo, String picJson,String picType) {
		int flag = 0;
		if(cmSeriesVo==null || cmSeriesVo.getF_ssc_name()==null) {
			flag = -1;
		}
		if(flag == 0) {
			cmSeriesVo.setF_ssc_code(cmSeriesVo.getF_ssc_code().replaceAll(" ", ""));
			contentDao.updateSeries(cmSeriesVo);
			updateSeriseCount(cmSeriesVo.getF_ssc_contentid());

			List<CmPicturesVo> picList = JsonUtils.jsonToPicVo(picJson);
			String listPicId = JsonUtils.jsonToPicIdList(picJson);
			int f_cv_relationid = cmSeriesVo.getF_ssc_id();
			Map<String,Object> picMap = new HashMap<String, Object>();
			picMap.put("listPicId", listPicId);
			picMap.put("f_cp_relationid", f_cv_relationid);
			picMap.put("picType", picType);
			pictureDao.deletePic(picMap);
			for(int i=0;i<picList.size();i++) {
				CmPicturesVo cmPicturesVo = new CmPicturesVo();
				cmPicturesVo = picList.get(i);
				cmPicturesVo.setF_cp_relationid(f_cv_relationid);
				pictureDao.insertPic(cmPicturesVo);
			}
			return 1;
		}
		return flag;
	}

	public Map<String,Object> selectBindContent(CmContentVo cmContentVo,int f_ccc_catalogid,int curPage,
												int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		cmContentVo.setF_cc_companyid(SQLCheckUtil.cleanXSS(cmContentVo.getF_cc_companyid()));
		cmContentVo.setF_cc_types(SQLCheckUtil.cleanXSS(cmContentVo.getF_cc_types()));
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		map.put("f_cc_name", cmContentVo.getF_cc_name());
		map.put("f_cc_status",cmContentVo.getF_cc_status());
		map.put("f_cc_companyid", cmContentVo.getF_cc_companyid());
		map.put("f_cc_types", cmContentVo.getF_cc_types());
		map.put("f_ccc_sdStatus",cmContentVo.getF_ccc_sdStatus());

		Integer rowCount = contentDao.findBindCount(map);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);

			List<CmContentVo> results = contentDao.selectBindContent(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<CmContentVo>());
		}
		return map;
	}

	public int findBindContentCount(CmContentVo cmContentVo,int f_ccc_catalogid){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		map.put("f_cc_name", cmContentVo.getF_cc_name());
		map.put("f_cc_status",cmContentVo.getF_cc_status());
		map.put("f_cc_companyid", cmContentVo.getF_cc_companyid());
		map.put("f_cc_types", cmContentVo.getF_cc_types());
		map.put("f_ccc_sdStatus",cmContentVo.getF_ccc_sdStatus());
		return contentDao.findBindCount(map);
	}

	public Map<String,Object> selectUnBindContent(CmContentVo cmContentVo,int f_ccc_catalogid,int curPage,
												  int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		cmContentVo.setF_cc_companyid(SQLCheckUtil.cleanXSS(cmContentVo.getF_cc_companyid()));
		cmContentVo.setF_cc_types(SQLCheckUtil.cleanXSS(cmContentVo.getF_cc_types()));
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		map.put("f_cc_name", cmContentVo.getF_cc_name());
		map.put("f_cc_status",cmContentVo.getF_cc_status());
		map.put("f_cc_companyid", cmContentVo.getF_cc_companyid());
		map.put("f_cc_types", cmContentVo.getF_cc_types());
		map.put("f_cc_programatype", cmContentVo.getF_cc_programatype());
		Integer rowCount = contentDao.findUnBindCount(map);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);

			List<CmContentVo> results = contentDao.selectUnBindContent(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<CmContentVo>());
		}
		return map;
	}

	/**
	 * 解除绑定
	 * @param f_ccc_catalogid
	 * @param f_ccc_contentid
	 * @param f_pu_id
	 * @return
	 */
	public int deleteBind(int f_ccc_catalogid,int f_ccc_contentid, String f_pu_id) {
		int flag = 0;
		if(f_ccc_catalogid <0 && f_ccc_contentid <0) {
			flag = -1;
		}
		if(flag == 0) {
			List<Integer> catalogList = contentDao.selectUserCatalogList(f_pu_id);
			if(catalogList.contains(f_ccc_catalogid)){
				CmCatalogContentVo cmCatalogContentVo = new CmCatalogContentVo();
				cmCatalogContentVo.setF_ccc_catalogid(f_ccc_catalogid);
				cmCatalogContentVo.setF_ccc_contentid(f_ccc_contentid);
				contentDao.deleteBind(cmCatalogContentVo);
				flag = 1;
			}
		}
		return flag;
	}


	public int insertBind(int f_ccc_catalogid,int f_ccc_contentid, String f_pu_id) {
		int flag = 0;
		if(f_ccc_catalogid <0 && f_ccc_contentid <0) {
			flag = -1;
		}
		if(flag == 0) {
			List<Integer> catalogList = contentDao.selectUserCatalogList(f_pu_id);
			if(catalogList.contains(f_ccc_catalogid)){
				CmCatalogContentVo cmCatalogContentVo = new CmCatalogContentVo();
				cmCatalogContentVo.setF_ccc_catalogid(f_ccc_catalogid);
				cmCatalogContentVo.setF_ccc_contentid(f_ccc_contentid);
				cmCatalogContentVo.setF_ccc_sdStatus(2);
				contentDao.insertBind(cmCatalogContentVo);
				flag = 1;
			}else{
				flag = -5;
			}
		}
		return flag;
	}

	/**
	 * 批量绑定
	 * @param f_ccc_catalogid
	 * @param ids
	 * @return
	 */
	public int batchBind(int f_ccc_catalogid, String ids, String f_pu_id) {
		int flag = 0;
		if(f_ccc_catalogid <= 0 || ids==null || ids.equals("")) {
			flag = -1;
		}
		if(flag == 0) {
			List<Integer> catalogList = contentDao.selectUserCatalogList(f_pu_id);
			if(catalogList.contains(f_ccc_catalogid)){
				String[] idArr = ids.split(",");
				for(int i=0; i<idArr.length;i++) {
					int f_ccc_contentid = Integer.valueOf(idArr[i]);
					CmCatalogContentVo cmCatalogContentVo = new CmCatalogContentVo();
					cmCatalogContentVo.setF_ccc_catalogid(f_ccc_catalogid);
					cmCatalogContentVo.setF_ccc_contentid(f_ccc_contentid);
					cmCatalogContentVo.setF_ccc_sdStatus(2);
					contentDao.insertBind(cmCatalogContentVo);
				}
				flag = 1;
			}else{
				flag = -5;
			}
		}
		return flag;
	}

	public int batchUnBind(int f_ccc_catalogid, String ids, String f_pu_id) {
		int flag = 0;
		if(f_ccc_catalogid <= 0 || ids==null || ids.equals("")) {
			flag = -1;
		}
		if(flag == 0) {
			List<Integer> catalogList = contentDao.selectUserCatalogList(f_pu_id);
			if(catalogList.contains(f_ccc_catalogid)){
				String[] idArr = ids.split(",");
				for(int i=0; i<idArr.length;i++) {
					int f_ccc_contentid = Integer.valueOf(idArr[i]);
					CmCatalogContentVo cmCatalogContentVo = new CmCatalogContentVo();
					cmCatalogContentVo.setF_ccc_catalogid(f_ccc_catalogid);
					cmCatalogContentVo.setF_ccc_contentid(f_ccc_contentid);
					contentDao.deleteBind(cmCatalogContentVo);
				}
				flag = 1;
			}else{
				flag = -5;
			}
		}
		return flag;
	}

	/**
	 * 查询内容绑定的分类列表
	 * @param f_cc_id
	 * @return
	 */
	public List<CmCatalogVo> selectContentBindCatalog(int f_cc_id) {
		return contentDao.selectContentBindCatalog(f_cc_id);
	}

	/**
	 * 根据f_ccc_contentid 查询 绑定的目录
	 * @param f_ccc_contentid
	 * @return
	 */
	public List<CmCatalogContentVo> selectCatalogBind(int f_ccc_contentid) {
		return contentDao.selectCatalogBind(f_ccc_contentid);
	}

	/**
	 * 根据f_cco_contentid 查询 绑定的目录
	 * @param f_cco_contentId
	 * @return
	 */
	public List<CmContentOrgVo> selectOrgBind(int f_cco_contentId) {
		return contentDao.selectOrgBind(f_cco_contentId);
	}

	/**
	 * 修改内容绑定的分类目录
	 * @param f_ccc_contentid
	 * @param cataloginStr
	 * @return
	 */
	public int updateCatalogBind(int f_ccc_contentid,String cataloginStr,String catalogdeStr, String orgIds) {
		int flag = 0;
		if(f_ccc_contentid <= 0) {
			flag = -1;
		} else if ((cataloginStr == null || cataloginStr.equals("")) && (catalogdeStr == null || catalogdeStr.equals(""))) {
			flag = -2;
		}
		if(flag == 0) {
			flag = 1;
			List<Integer> catalogList = contentDao.selectUserCatalogList(orgIds);
			List<CmCatalogContentVo> delist = new ArrayList<CmCatalogContentVo>();
			List<CmCatalogContentVo> inlist = new ArrayList<CmCatalogContentVo>();
			if (catalogdeStr != null && !catalogdeStr.equals("")) {
				String[] decatalogIds = catalogdeStr.split(",");
				for(String str:decatalogIds) {
					int f_ccc_catalogid = Integer.valueOf(str);
					if(catalogList.contains(f_ccc_catalogid)){
						CmCatalogContentVo catalogContentVo = new CmCatalogContentVo();
						catalogContentVo.setF_ccc_contentid(f_ccc_contentid);
						catalogContentVo.setF_ccc_catalogid(f_ccc_catalogid);
						delist.add(catalogContentVo);
					}else{
						flag = -5;
						break;
					}
				}
			}
			if (cataloginStr != null && !cataloginStr.equals("") && flag != -5) {
				String[] incatalogIds = cataloginStr.split(",");
				for(String str:incatalogIds) {
					int f_ccc_catalogid = Integer.valueOf(str);
					if(catalogList.contains(f_ccc_catalogid)){
						CmCatalogContentVo catalogContentVo = new CmCatalogContentVo();
						catalogContentVo.setF_ccc_contentid(f_ccc_contentid);
						catalogContentVo.setF_ccc_catalogid(Integer.valueOf(str));
						inlist.add(catalogContentVo);
					}else{
						flag = -5;
						break;
					}
				}
			}

			//全部有权限后， 执行操作
			if(flag != -5){
				for(CmCatalogContentVo cc : delist){
					contentDao.deleteBind(cc);
				}
				for(CmCatalogContentVo cc : inlist){
					contentDao.insertBind(cc);
				}
			}
		}
		return flag;
	}

	public CmCatalogContentVo selectViewIndex(CmCatalogContentVo cmCatalogContentVo) {
		return contentDao.selectViewIndex(cmCatalogContentVo);
	}

	public int updateViewIndex(CmCatalogContentVo cmCatalogContentVo) {
		int flag = 0;
		if(cmCatalogContentVo==null) {
			flag = -1;
		}
		if(flag == 0) {
			contentDao.updateViewIndex(cmCatalogContentVo);
			return 1;
		}
		return flag;
	}

	/**
	 * 更新对应剧头表cm_content中f_cc_seriescount字段，非事务性方法调用，可能会导致数据不正确问题，建议后续考虑更好的办法
	 * @param f_ssc_contentid
	 * @return
	 */
	public int updateSeriseCount(int f_ssc_contentid) {
		int flag = 0;
		int seriseCount = contentDao.selectSeriesCount(f_ssc_contentid);
		CmContentVo ccv = new CmContentVo();
		ccv.setF_cc_id(f_ssc_contentid);
		ccv.setF_cc_seriescount(seriseCount);
		flag = contentDao.updateSeriseCount(ccv);
		return flag;
	}

	public int updateBatchCount(String f_cc_name, String f_cc_code, String f_cc_obligate1) {
		int flag = 0;
		CmContentVo ccv = new CmContentVo();
		ccv.setF_cc_name(f_cc_name);
		ccv.setF_cc_code(f_cc_code);
		ccv.setF_cc_obligate1(f_cc_obligate1);
		ccv.setF_cc_status(1);
		flag = contentDao.updateBatchCount(ccv);
		return flag;
	}

	public int batchReviewContent(String ids) {
		int flag = 0;
		String[] idsArr = ids.split(",");
		for(int i=0;i<idsArr.length;i++) {
			CmContentVo content = new CmContentVo();
			content.setF_cc_id(Integer.valueOf(idsArr[i]));
			content.setF_cc_status(1);
			content.setF_cc_remark("");
			flag += contentDao.reviewContent(content);
		}
		return flag;
	}

	public int batchDeleteContent(String ids) {
		int flag = 0;
		String[] idsArr = ids.split(",");
		for(int i=0;i<idsArr.length;i++) {
			flag += contentDao.deleteContent(Integer.valueOf(idsArr[i]));
		}
		return flag;
	}

	public int batchUnReviewContent(String ids) {
		int flag = 0;
		String[] idsArr = ids.split(",");
		for(int i=0;i<idsArr.length;i++) {
			CmContentVo content = new CmContentVo();
			content.setF_cc_id(Integer.valueOf(idsArr[i]));
			content.setF_cc_status(2);
			content.setF_cc_remark("");
			flag += contentDao.reviewContent(content);
		}
		return flag;
	}

	public int updateContentStatus(int f_cc_id,int f_cc_status) {
		int flag = 0;
		flag = contentDao.updateContentStatus(f_cc_id,f_cc_status);
		return flag;
	}

	public int updateContentCode(int f_cc_id, String f_cc_code) {
		int flag = 0;
		flag = contentDao.updateContentCode(f_cc_id,f_cc_code);
		return flag;
	}

	public Map<String,Object> selectOrgListByModelId(PmsOrgVo orgVo,int curPage,
													 int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount =contentDao.selectOrgListByModelIdCount(orgVo);
		map.put("total", rowCount);
		if(rowCount!=null&&rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_po_name", orgVo.getF_po_name());
			map.put("f_po_model", orgVo.getF_po_model());
			map.put("sorg_startDate", orgVo.getSorg_startDate());
			map.put("sorg_endDate", orgVo.getSorg_endDate());
			List<PmsOrgVo> orgList=contentDao.selectOrgListByModelId(map);
			map.put("rows", orgList);
		} else {
			map.put("rows", new ArrayList<CmSeriesVo>());
		}
		return map;
	}

	public List<PmsOrgVo> selectOrgListByModelIdAll(PmsOrgVo orgVo) {
		Integer rowCount =contentDao.selectOrgListByModelIdCount(orgVo);
		List<PmsOrgVo> orgList=new ArrayList<PmsOrgVo>();
		if(rowCount!=null&&rowCount > 0) {
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("firstResult", 0);
			map.put("maxResults", rowCount);
			map.put("f_po_name", orgVo.getF_po_name());
			map.put("f_po_model", orgVo.getF_po_model());
			map.put("sorg_startDate", orgVo.getSorg_startDate());
			map.put("sorg_endDate", orgVo.getSorg_endDate());
			orgList=contentDao.selectOrgListByModelId(map);
		}
		return orgList;
	}

	public String industryBatchInsertContent(MultipartFile file, String f_cc_companyid) {
		int successCount = 0;
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		JSONArray emptyArr = new JSONArray();
		StringBuffer str = new StringBuffer();
		StringBuffer str2 = new StringBuffer();
		InputStream is = null;
		try {
			LOG.debug("批量导入content开始");
			is = file.getInputStream();
			List<Map<String, Object>> list = ExcelUtil.parseExcel(is, ExcelUtil.ALLOWED_EMPTY_MODE, new String[]{});

			CmContentVo tmpVo = new CmContentVo();
			tmpVo.setF_cc_companyid(f_cc_companyid);
			int existingAccount = verificationExistingAccounts(tmpVo,list.size());
			if(existingAccount==0){
				LOG.debug("解析excel完成, 开始循环入库");
				//10年后
				String offlineDate = "2099-12-31 23:59:59";
				String onlineDate = format.format(new Date());
				for(int i=0;i<list.size();i++){
					try {
						Map<String, Object> m = list.get(i);
						CmContentVo content = ConvertBeanUtil.getBeanFromMap(m, CmContentVo.class, "userServeridTypeList");
						content.setF_cc_isfree(0);
						content.setF_cc_status(1);
						content.setF_cc_onlinedate(onlineDate);
						content.setF_cc_offlinedate(offlineDate);
						content.setF_cc_companyid(f_cc_companyid);
						content.setF_cc_seriescount(1);
						content.setF_cc_end(0);
						content.setF_cc_type(100);
						content.setF_cc_name(content.getF_cc_name().trim());
						content.setF_cc_programatype("1");
						boolean success = false;

						CmContentVo cc = new CmContentVo();
						cc.setF_cc_type(content.getF_cc_type());
						cc.setF_cc_name2(content.getF_cc_name());
						Map<String, Object> result = this.selectContentList(cc, 1, 1);
						if((Integer) result.get("total") > 0){
							str.append("帐号重复: ").append(content.getF_cc_name()).append("<br/>");
						} else {
							Map<String,Object> resultMap = this.insertContent(content, emptyArr.toJSONString());
							success = (Boolean) resultMap.get("success");
						}

						successCount += (success ? 1 : 0);
						if(!success) {
							str2.append(i+1).append(",");
						}
					} catch (Exception e) {
						LOG.error("", e);
					//	str.append("第").append(i+1).append("条 出错! ").append(e.getMessage()).append("<br/>");
					}
				}
				LOG.debug("批量完成");
				if(str2.length() > 0) {
					str.append("第").append(str2.substring(0, str2.length() - 1)).append("条导入失败! ").append("<br/>");
				}
				str.append("批量导入完成， 一共：").append(list.size()).append("条数据, 成功").append(successCount).append(", 失败").append(list.size() - successCount);
			}else{
				str.append("用户数录入已超过"+existingAccount+"个，若要继续录入，需向省公司发起申请！");
			}

		} catch (Exception e) {
			LOG.error("", e);
		//	str.append("批量导入失败: " + e.getMessage());
		}finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
				}
			}
		}

		return str.toString();
	}
	public int insertCmContentLadger(CmContentLedgerVo cmContentLedger){
		return contentDao.insertCmContentLadger(cmContentLedger);
	}
	public int modelFileDecompression(CmContentVo contentVo,String f_cp_url){
		int flag=-9;
		try{
			LOG.debug("解析模板"+contentVo.getF_cc_name()+"的文件："+SystemConfigUtils.getSysConfig("system_decompression_path")+f_cp_url);
			if(readZipFile(SystemConfigUtils.getSysConfig("system_decompression_path")+f_cp_url)){
				return -10;
			}

			String isCurrency="commons";
			if(contentVo.getF_cc_isfree()==1){
				isCurrency="individuation";
			}
			int modelIndex=0;//需要获取
			SysConfigVo sysConfigVo=sysConfigServiceBeen.selectSystemByKey("system_decompression_index");
			if(sysConfigVo!=null){
				modelIndex=Integer.parseInt(sysConfigVo.getF_sc_value());
			}else{
				return flag;
			}
			String model_now=contentVo.getF_cc_desc();
			if(model_now==null||"".equals(model_now)){//已存在解压路径
				//需要获取系统配置文件名称编号
				if(modelIndex!=0){
					String mobleUrl=isCurrency+"/external_"+modelIndex;
					String decompressionFile=SystemConfigUtils.getSysConfig("system_decompression_path")+"PIC/model/"+mobleUrl;//解压路径
					String filePath=SystemConfigUtils.getSysConfig("system_decompression_path")+f_cp_url;//文件路径
					try {
						if(contentVo.getF_ccc_viewindex()==2){//审核时将目录解压至审核目录
							decompressionFile=decompressionFile.replace("commons", "review");
							decompressionFile=decompressionFile.replace("individuation", "review");
						}
						LOG.debug("解压文件filePath=="+filePath+"\n 解压目录decompressionFile="+decompressionFile);
						DeCompressUtil.decompressionFun(filePath,decompressionFile);
						contentVo.setF_cc_desc(mobleUrl+"/index.html");
						contentDao.updateContent(contentVo);
					} catch (Exception e) {
						LOG.error("新键目录时，出现错误：未完成文件解压！解压文件filePath=="+filePath+"\n 解压目录decompressionFile="+decompressionFile,e);
					}
					sysConfigVo.setF_sc_value(String.valueOf(++modelIndex));
					sysConfigServiceBeen.updateSystem(sysConfigVo);//将配置值加一
				}
			}else{
				String mobleUrl=model_now.substring(0, model_now.lastIndexOf("/"));
				String decompressionFile=SystemConfigUtils.getSysConfig("system_decompression_path")+"PIC/model/"+mobleUrl;//解压路径
				String backupsFile=SystemConfigUtils.getSysConfig("system_decompression_path")+"backups/model/"+PublicUtil.getCurDateTime("yyMMdd")+"/"+mobleUrl;//备份目录，移出同步目录
				if(contentVo.getF_ccc_viewindex()==2){//审核时将目录解压至审核目录
					decompressionFile=decompressionFile.replace("commons", "review");
					decompressionFile=decompressionFile.replace("individuation", "review");
				}
				String filePath=SystemConfigUtils.getSysConfig("system_decompression_path")+f_cp_url;//文件路径
				File file=new File(decompressionFile);
				boolean isExist=file.exists();
				if(isExist){//解压目录下确实存在此文件
					FileUtil.copy_commons(decompressionFile,backupsFile+"_save"+PublicUtil.getCurDateTime("yyMMddhhmmss"));
					//boolean xx=file.renameTo(new File(decompressionFile+"_save"+PublicUtil.getCurDateTime("yyMMddhhmmss")));
				}
				try {
					LOG.debug("已存在目录——解压文件filePath=="+filePath+"\n 解压目录decompressionFile="+decompressionFile);
					DeCompressUtil.decompressionFun(filePath,decompressionFile);
					contentVo.setF_cc_desc(mobleUrl+"/index.html");
					contentDao.updateContent(contentVo);
				} catch (Exception e) {
					LOG.error("已存在目录解压时出现错误：未完成文件解压！解压文件filePath=="+filePath+"\n 解压目录decompressionFile="+decompressionFile,e);
				}
				/*if(!isExist){//不存在解压目录时正常解压入库
					sysConfigVo.setF_sc_value(String.valueOf(++modelIndex));
					sysConfigServiceBeen.updateSystem(sysConfigVo);//将配置值加一
				}*/
			}
			flag=0;
		}catch(Exception e){
			LOG.error("解压失败contentid="+contentVo.getF_cc_id()+"||f_cp_url"+f_cp_url,e);
		}
		return flag;
	}
	public void readDecompressionFile(String file,CmContentVo contentVo){
		ZipFile zf=null;
		InputStream in=null;
		ZipInputStream zin=null;
		try{
			zf = new ZipFile(file);
			in = new BufferedInputStream(new FileInputStream(file));
			zin = new ZipInputStream(in);
			ZipEntry ze;
			List<String> strList=new ArrayList<String>();
			while ((ze = zin.getNextEntry()) != null) { //解析zip包
				if (ze.isDirectory()) {
				} else {

					long size = ze.getSize();
					if (size > 0&&(ze.getName().endsWith(".jsp")||ze.getName().endsWith(".JSP")||ze.getName().endsWith(".html"))) { //对jsp进行判断
						StringBuilder sb=new StringBuilder();
						BufferedReader br = new BufferedReader(
								new InputStreamReader(zf.getInputStream(ze)));
						String line;
						while ((line = br.readLine()) != null) {
							sb.append(line);
						}

						br.close();
						Pattern patternHttpUrl = Pattern.compile("http://[^\"]*\"|http://[^']*'|igmp://(((25[0-5]|2[0-4]\\d|1?\\d?\\d)\\.){3}(25[0-5]|2[0-4]\\d|1?\\d?\\d))(:[0-9]{1,4})");

						Matcher matcherHttpUrl = patternHttpUrl.matcher(sb.toString());
						while(matcherHttpUrl.find()){
							String url=matcherHttpUrl.group();
							url=url.replaceAll("(\"|\')", "");
							if(url.endsWith("\\")){
								url=url.substring(0, url.length()-1);
							}
							if(url.indexOf("?")>0){
								url=url.substring(0, url.indexOf("?"));
							}
							url=url.trim();
							strList.add(url);
						}
					}
				}
			}
	    /*、存在外链就记录，统一需要调整调用方法
	     *  List<WlContentVo> outerChain= waiLianDao.selectWlContent();
	     Iterator<String> it=strList.iterator();
	        //去除数组中"a"的元素
	        while(it.hasNext()){
	            String st=it.next();
	            for(int j=0;j<outerChain.size();j++){
		    		 if(st.indexOf(outerChain.get(j).getF_wlc_path())>=0||(outerChain.get(j)!=null&&outerChain.get(j).getF_wlc_path().indexOf(st)>=0)){
		    			 it.remove();
		    			 LOG.debug("跳出循环"+st+"=="+outerChain.get(j));
		    			 break;
			    	 }
		    	 }
	        }
	       */
			contentVo.setF_cc_obligate1(strList.toString());
		}catch(Exception e){
			LOG.error("解析模板压缩包出错",e);
		}finally{
			try{
				if(zin!=null)
					zin.closeEntry();
			}catch(IOException e){
				LOG.error("Zin对象IO关闭失败",e);
			}
			try{
				if(zf!=null)
					zf.close();
			}catch(IOException e){
				LOG.error("zf对象IO关闭失败",e);
			}
			try{
				if(in!=null)
				in.close();
			}catch(IOException e){
				LOG.error("in对象IO关闭失败",e);
			}
		}
	}
	public boolean readZipFile(String file){
		boolean falg=false;
		ZipFile zf = null;
		FileInputStream fis = null;
		InputStream in = null;
		try{
			zf=new ZipFile(file);
			fis = new FileInputStream(file);
			in = new BufferedInputStream(fis);
			ZipInputStream zin = new ZipInputStream(in);
			ZipEntry ze;
			while ((ze = zin.getNextEntry()) != null) { //解析zip包
				if (ze.isDirectory()) {
				} else {

					long size = ze.getSize();
					if (size > 0&&(ze.getName().endsWith(".jsp")||ze.getName().endsWith(".JSP"))) { //对jsp进行判断
						StringBuilder sb=new StringBuilder();
						BufferedReader br = new BufferedReader(
								new InputStreamReader(zf.getInputStream(ze)));
						String line;
						while ((line = br.readLine()) != null) {
							sb.append(line);
						}
						br.close();
						Pattern patternJavaIO = Pattern.compile("java.io.");//禁止使用IO
						Matcher matcher = patternJavaIO.matcher(sb.toString());
						while(matcher.find()){//遍历jsp判断是否存在io流
							LOG.debug("禁止使用IO,存在"+matcher.group());
							return true;
						}
						Pattern patternJavaSql = Pattern.compile("java.sql.");//禁止使用数据库类
						Matcher matcherSql = patternJavaSql.matcher(sb.toString());
						while(matcherSql.find()){//遍历jsp判断是否存在io流
							LOG.debug("禁止使用数据库类,存在"+matcherSql.group());
							return true;
						}
						Pattern patternSystemProperty = Pattern.compile("System.getProperty");//禁止获取系统属性
						Matcher matcherSp = patternSystemProperty.matcher(sb.toString());
						while(matcherSp.find()){//遍历jsp判断是否存在io流
							LOG.debug("禁止获取系统属性,存在"+matcherSp.group());
							return true;
						}
						Pattern patternLangAll = Pattern.compile("java.lang.\\*");//禁止获取java。lang全部类
						Matcher matcherLangAll = patternLangAll.matcher(sb.toString());
						while(matcherLangAll.find()){//遍历jsp判断是否存在io流
							LOG.debug("禁止获取java。lang全部类,存在"+matcherLangAll.group());
							return true;
						}
						Pattern patternLangSystem = Pattern.compile("java.lang.System");//禁止获取系统类
						Matcher matcherLangSystem = patternLangSystem.matcher(sb.toString());
						while(matcherLangSystem.find()){//遍历jsp判断是否存在io流
							LOG.debug("禁止获取系统类,存在"+matcherLangSystem.group());
							return true;
						}
						Pattern patternLangProcess = Pattern.compile("java.lang.Process");//禁止获取进程类
						Matcher matcherLangProcess = patternLangProcess.matcher(sb.toString());
						while(matcherLangProcess.find()){//遍历jsp判断是否存在io流
							LOG.debug("禁止获取进程类,存在"+matcherLangProcess.group());
							return true;
						}
						Pattern patternLangProcessBuilder = Pattern.compile("java.lang.ProcessBuilder");//禁止操作进程
						Matcher matcherLangProcessBuilder = patternLangProcessBuilder.matcher(sb.toString());
						while(matcherLangProcessBuilder.find()){//遍历jsp判断是否存在io流
							LOG.debug("禁止操作进程,存在"+matcherLangProcessBuilder.group());
							return true;
						}
					}
				}
			}
			try{
				zin.closeEntry();
			}catch(IOException e){
				LOG.error("Zin对象IO关闭失败",e);
			}
			try{
				if(zf!=null)
					zf.close();
			}catch(IOException e){
				LOG.error("zf对象IO关闭失败",e);
			}
		}catch(Exception e){
			LOG.error("解析模板压缩包出错",e);
			falg=true;
		}finally {
			if (fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
				}
			}
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
				}
			}
			if (zf != null) {
				try {
					zf.close();
				} catch (IOException e) {
				}
			}
		}
		return falg;
	}

	public int verificationExistingAccounts(CmContentVo cmContentVo,int size) {
		String arr[] = cmContentVo.getF_cc_companyid().split(",");
		int count=0;
		int verificationExistingAccount=0;
		for(int i=0;i<arr.length;i++){
			CmContentVo tmpVo = new CmContentVo();
			tmpVo.setF_cc_status(1);
			tmpVo.setF_cc_type(100);
			tmpVo.setF_cc_companyid(arr[i]);
			Integer existingAccount = contentDao.findContentCount(tmpVo);
			PmsOrgVo pmsOrgVo = pmsServiceBean.selectOrg(Integer.parseInt(arr[i]));
			verificationExistingAccount = pmsOrgVo.getF_po_limitcount();
			if(pmsOrgVo.getF_po_limitcount()!=0){
				if(existingAccount+size>pmsOrgVo.getF_po_limitcount()){
					count=1;
				}
			}

		}
		if(count==0){
			return 0;
		}else{
			return verificationExistingAccount;
		}


	}

	public Map<String, Object> selectVoteContent(CmContentVo cmContentVo,  String f_csvt_activityid, String min_num, String max_num, String f_catalog_starttime, String f_catalog_endtime, String f_catalog_id,String catalogIds, int curPage, int pageSize) {

		Map<String,Object> map = new HashMap<String, Object>();

		if(min_num!=""&&min_num!=null){
			map.put("min_num", Integer.parseInt(min_num));
		}
		if(max_num!=""&&max_num!=null){
			map.put("max_num", Integer.parseInt(max_num));
		}
		map.put("f_cc_searchname", cmContentVo.getF_cc_searchname());
		map.put("f_cc_name", cmContentVo.getF_cc_name());
		map.put("f_cc_obligate2", cmContentVo.getF_cc_obligate2());
		map.put("f_cc_obligate1", cmContentVo.getF_cc_obligate1());
		map.put("f_csvt_activityid",f_csvt_activityid);
		map.put("f_catalog_starttime", f_catalog_starttime);
		map.put("f_catalog_endtime", f_catalog_endtime);
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_catalog_ids", catalogIds);
		Integer rowCount = contentDao.findVoteCount(map);
		map.put("total", rowCount);
		if(rowCount!=null){
			if(rowCount > 0 && curPage > 0 && pageSize > 0) {
				map.put("firstResult", (curPage-1)*pageSize);
				map.put("maxResults", pageSize);

				List<CmContentVo> results = contentDao.selectVoteContent(map);
				map.put("rows", results);
			} else {
				map.put("rows", new ArrayList<CmContentVo>());
			}
		}
		return map;
	}

	public Map<String, Object> vote_bind_excel(CmContentVo cmContentVo,  String f_csvt_activityid, String min_num, String max_num, String f_catalog_starttime, String f_catalog_endtime, String f_catalog_id,String catalogIds) {

		Map<String,Object> map = new HashMap<String, Object>();

		if(min_num!=""&&min_num!=null){
			map.put("min_num", Integer.parseInt(min_num));
		}
		if(max_num!=""&&max_num!=null){
			map.put("max_num", Integer.parseInt(max_num));
		}
		map.put("f_cc_searchname", cmContentVo.getF_cc_searchname());
		map.put("f_cc_name", cmContentVo.getF_cc_name());
		map.put("f_cc_obligate2", cmContentVo.getF_cc_obligate2());
		map.put("f_cc_obligate1", cmContentVo.getF_cc_obligate1());
		map.put("f_csvt_activityid",f_csvt_activityid);
		map.put("f_catalog_starttime", f_catalog_starttime);
		map.put("f_catalog_endtime", f_catalog_endtime);
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_catalog_ids", catalogIds);
		Integer rowCount = contentDao.findVoteCount(map);
		map.put("total", rowCount);
		if(rowCount!=null){
			if(rowCount > 0) {
				map.put("firstResult", 0);
				map.put("maxResults", rowCount);
				List<CmContentVo> results = contentDao.selectVoteContent(map);
				map.put("rows", results);
			} else {
				map.put("rows", new ArrayList<CmContentVo>());
			}
		} else {
			map.put("rows", new ArrayList<CmContentVo>());
		}
		return map;
	}

	public Map<String, Object> selectVoteUser(AcVoteUserLikeVo acVoteUserLikeVo, int curPage, int pageSize) {
		Map<String, Object> map = new HashMap<>();
		map.put("f_cc_id", acVoteUserLikeVo.getF_avu_contentid());
		map.put("f_avu_serverid", acVoteUserLikeVo.getF_avu_serverid());
		map.put("f_avu_activityid", acVoteUserLikeVo.getF_avu_activityid());
		Integer rowCount = contentDao.finVoteUserCount(map);
		map.put("total", rowCount);
		if(rowCount!=null){
			if(rowCount > 0 && curPage > 0 && pageSize > 0) {
				map.put("firstResult", (curPage-1)*pageSize);
				map.put("maxResults", pageSize);
				List<AcVoteUserLikeVo> results= contentDao.selectVoteUser(map);
				map.put("rows", results);
			} else {
				map.put("rows", new ArrayList<AcVoteUserLikeVo>());
			}
		}else{
			map.put("rows", new ArrayList<AcVoteUserLikeVo>());
		}
		return map;
	}

	public CmVoteTotalVo selectVotaByContenId(int contentid, String activityid) {
		Map<String, Object> map = new HashMap<>();
		map.put("f_csvt_contentid", contentid);
		map.put("f_csvt_activityid",activityid);
		CmVoteTotalVo cmVoteTotalVo =contentDao.selectVotaByContenId(map);
		return cmVoteTotalVo;
	}

	public int updateVote(int count, int contentid, String activityid) {
		Map<String, Object> map = new HashMap<>();
		map.put("f_csvt_contentid", contentid);
		map.put("f_csvt_votecount", count);
		map.put("f_csvt_activityid",activityid);
		int flag = contentDao.updateVote(map);
		return flag;
	}

	public int insertVoteUser(AcVoteUserLikeVo acVoteUserLikeVo) {
		int flag = contentDao.insertVoteUser(acVoteUserLikeVo);
		return flag ;
	}

	public int insertVote(CmVoteTotalVo cmVoteTotalVo) {
		cmVoteTotalVo.setF_csvt_status(1);
		int flag = contentDao.insertVote(cmVoteTotalVo);
		return flag ;
	}

	public List<CmContentProductVo> selectProductBind(int f_ccp_contentId) {
		return contentDao.selectProductBind(f_ccp_contentId);
	}

	public int updateSdStatusHistory(int f_ccc_catalogid,int maxResults){
		Map<String,Object> map = new HashMap<>();
		map.put("f_ccc_catalogid",f_ccc_catalogid);
		map.put("maxResults",maxResults);
		return contentDao.updateSdStatusHistory(map);
	}
}
